package com.fzy.connect;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

import com.fzy.Source.Source;

public class LoginTest extends Thread {
	DatagramSocket ds = null;
	DatagramPacket getDp;

	public void run() {
		try {
			ds = new DatagramSocket(Source.LOGIN_TEST);
			byte[] buffer = new byte[1024];
			getDp = new DatagramPacket(buffer, buffer.length);
			while (true) {
				ds.receive(getDp);
				int length = getDp.getLength();
				byte[] get = getDp.getData();
				String message = new String(get, 0, length);
				String[] result = message.split("#");

				// OP#IP#ID
				if (ID.LOGIN_TEST == Integer.parseInt(result[0])) {
					int id = Integer.parseInt(result[2]);
					Source.userLogin(id, result[1]);
				}
			}
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}